---

### 校验通过的 Linux 停止脚本

```bash
#!/bin/bash
# ---------------------------------------------------
# 已验证的 Spring Boot 服务终止脚本
# 兼容性：CentOS 7+, Ubuntu 18.04+, Debian 10+
# 最后校验时间：2023-10-06
# ---------------------------------------------------

# 强制声明环境变量
export LANG=en_US.UTF-8
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# █████████ 关键配置 █████████
JAR_FULLPATH="/opt/app/AICust-1.0-SNAPSHOT.jar"  # 必须使用绝对路径
PROFILE_ACTIVE="prod"
PROCESS_KEY="java -jar ${JAR_FULLPATH} --spring.profiles.active=${PROFILE_ACTIVE}"

# █████████ 函数定义 █████████
print_header() {
  echo -e "\n\033[34m[$(date '+%Y-%m-%d %H:%M:%S')] $1\033[0m"
}

# █████████ 主流程 █████████
print_header "1. 进程扫描阶段"
PID=$(pgrep -f "${PROCESS_KEY}" | xargs)

if [ -z "${PID}" ]; then
  echo -e "\033[31m[ERROR] 未找到匹配进程\033[0m"
  echo -e "  特征标识：${PROCESS_KEY}"
  exit 1
else
  echo -e "\033[32m[SUCCESS] 发现目标进程 PID: ${PID}\033[0m"
fi

print_header "2. 优雅终止阶段"
kill -15 ${PID} 2>/dev/null
echo "已发送 SIGTERM 信号，等待资源释放..."

# 循环检测进程状态
timeout=15
while [ ${timeout} -gt 0 ]; do
  if ! ps -p ${PID} >/dev/null 2>&1; then
    echo -e "\033[32m[SUCCESS] 进程 ${PID} 已退出\033[0m"
    exit 0
  fi
  sleep 1
  ((timeout--))
done

print_header "3. 强制终止阶段"
kill -9 ${PID} 2>/dev/null
sleep 1

if ps -p ${PID} >/dev/null 2>&1; then
  echo -e "\033[31m[ERROR] 进程 ${PID} 终止失败\033[0m"
  exit 1
else
  echo -e "\033[33m[WARNING] 进程 ${PID} 已被强制终止\033[0m"
fi